package com.wwwarehouse.usercenter.fragment.review;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;

import com.wwwarehouse.usercenter.R;


/**
 * @author : mundane
 * @time : 2017/8/17 11:00
 * @description :
 * @file : MyDialogFragment.java
 */

public class GuideNewUserDialogFragment extends DialogFragment {

	private ImageView mIv;

	public GuideNewUserDialogFragment() {
	}

	private int mCount;

	public static GuideNewUserDialogFragment newInstance() {
		GuideNewUserDialogFragment dialogFragment = new GuideNewUserDialogFragment();
		return dialogFragment;
	}

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 这个会把状态栏都遮住
//		setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Wallpaper_NoTitleBar_Fullscreen);
//		setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		// 这个只是全屏, 但是不会把状态栏遮住
		setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar);
	}

	public interface OnDismissListener {
		void onDismiss();
	}

	private OnDismissListener mOnDismissListener;

	public void setOnDismissListener(OnDismissListener onDismissListener) {
		mOnDismissListener = onDismissListener;
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		//此处在子类中设置点击对话框外部，对话框不消失
		getDialog().setCancelable(false);
		getDialog().setCanceledOnTouchOutside(false);
//		//设置对话框背景色，否则有虚框
		getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		View rootView = inflater.inflate(R.layout.dialog_fragment_newuser_guide, container, false);
		return rootView;
	}

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		mIv = (ImageView) view.findViewById(R.id.iv);
		mIv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				switch (mCount) {
					case 0:
						mIv.setImageResource(R.drawable.bg_guide2);
						break;
					case 1:
						mIv.setImageResource(R.drawable.bg_guide3);
						break;
					case 2:
						mIv.setImageResource(R.drawable.bg_guide4);
						break;
					case 3:
						mIv.setImageResource(R.drawable.bg_guide5);
						break;
					default:
						GuideNewUserDialogFragment.this.dismiss();
						break;
				}
				mCount++;

			}
		});
	}

}
